package arena;

import robot.Robot;
import graphics.Grid;
import graphics.Point;
import java.awt.Color;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

/**
 * Container object which builds an arena.  An arena consists of a hashmap
 * containing node objects and another hashmap containing robot objects.
 * The nodeMap contains all of the nodes used by the arena and the robotMap
 * contains all of the robots that are attached to the arena.
 *
 * @author      Gabriel Loewen
 * @author      James Weston
 * @author      Jackie O'Quinn
 */
public class Arena {

    //Define the hashmap of nodes and hashmap of robots
    public HashMap<String, Node> nodeMap = new HashMap<String, Node>();
    public HashMap<String, Robot> robotMap = new HashMap<String, Robot>();
    //Define width and height of the arena
    public int width;
    public int height;
    //Define the grid object that is owned by this arena
    private Grid grid;

    /**
     * Constructor.  Takes a width and a height and constructs a grid object
     * with the specified size.
     * @param   w   The width of the arena
     * @param   h   The height of the arena
     */
    public Arena(int w, int h) {

        this.width = w;
        this.height = h;

        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                nodeMap.put((String) (i + "," + j), new Node(new Point(i, j)));
            }
        }
        grid = new Grid(this);

    }

    /**
     * Returns the grid object which is used by this arena
     * @return The grid object
     */
    public Grid getGrid() {
        return this.grid;
    }

    //changes all nodes but the robot nodes to UNKNOWN
    public void reset(){
        Set<Entry<String, Node>> set = criep.CRIEP.PhysicalArena.nodeMap.entrySet();
        Iterator<Entry<String, Node>> iter = set.iterator();

        while(iter.hasNext()){
            Node node = iter.next().getValue();
            if(node.isOccupied)
                node.setColor(Color.BLACK);
            else
                node.setColor(Color.GRAY);
        }
    }
}
